package com.example.carbon.server.info;

import com.alibaba.fastjson2.JSON;
import com.example.carbon.dao.EnergyDataDao;
import com.example.carbon.pojo.dto.EnergySearch;
import com.example.carbon.pojo.dto.PageLimit;
import com.example.carbon.pojo.vo.TableData;
import com.example.carbon.server.EnergyServerInfo;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class EnergyServer implements EnergyServerInfo {
    @Resource
    EnergyDataDao energyDataDao;
    /**
     * 进行分页返回数据的server
     * @param pageLimit
     * @return
     */
    @Override
    public String getEnergyInfo(PageLimit pageLimit, EnergySearch search) {
       log.info(energyDataDao.selectAllInfo(pageLimit, search).toString());
       log.info(energyDataDao.getTableCount(search)+"");
        try {
            TableData tableData=new TableData<>(energyDataDao.selectAllInfo(pageLimit, search)
                    ,energyDataDao.getTableCount(search));
            return JSON.toJSONString(tableData);
        }catch (Exception e){
            log.info(e.getMessage());
            return null;
        }
    }

}
